package com.wordplat.quickstart.xutils.common.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * \
 * MD5
 *
 * @since 2021-05-08
 */
public final class MD5 {
    private static final String strMd5 = "MD5";
    private static final String utf8 = "UTF-8";
    private static final char[] CHARS =
            {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    private MD5() {
    }

    /**
     * toHexString
     *
     * @param bytes
     * @return String
     */
    public static String toHexString(byte[] bytes) {
        if (bytes == null) {
            return "";
        }
        StringBuilder hex = new StringBuilder(bytes.length * 2);
        for (byte b : bytes) {
            hex.append(CHARS[(b >> 4) & 0x0F]);
            hex.append(CHARS[b & 0x0F]);
        }
        return hex.toString();
    }
}
